package cn.jeefast.modules.platform.controller;


import cn.jeefast.common.entity.MbResearchData;
import cn.jeefast.common.entity.MbResearchSetpDataDetail;
import cn.jeefast.common.utils.R;
import cn.jeefast.modules.platform.service.MbResearchData1Service;
import cn.jeefast.modules.platform.service.MbResearchSetpDataDetail1Service;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import cn.jeefast.common.base.BaseController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author theodo
 * @since 2020-01-06
 */
@RestController
@RequestMapping("/mbResearchSetpDataDetail")
@CrossOrigin
public class MbResearchSetpDataDetail1Controller extends BaseController {

    @Autowired
    private MbResearchSetpDataDetail1Service mbResearchSetpDataDetailService;

    @Autowired
    private MbResearchData1Service mbResearchDataService;

    /**
     * 更新
     * @param list
     * @return
     */
    @RequestMapping("/update")
    public R update(@RequestBody List<MbResearchSetpDataDetail> list){
        for (MbResearchSetpDataDetail mrd:list
             ) {
            mbResearchSetpDataDetailService.updateById(mrd);
        }
        return R.ok();
    }

    /**
     * 数据分析页面详细数据部分
     * @param dataId
     * @return
     */
    @RequestMapping("/detail")
    public R dataDetail(Long dataId){
        MbResearchData mbResearchData = mbResearchDataService.selectById(dataId);
        List<Map> img = new ArrayList<>();
        if(mbResearchData.getDataImg1()!=null){
            Map m = new HashMap();
            m.put("url",mbResearchData.getDataImg1());
            m.put("time",mbResearchData.getDataImg1Time());
            img.add(m);
        }
        if(mbResearchData.getDataImg2()!=null){
            Map m = new HashMap();
            m.put("url",mbResearchData.getDataImg2());
            m.put("time",mbResearchData.getDataImg2Time());
        }
        if(mbResearchData.getDataImg3()!=null){
            Map m = new HashMap();
            m.put("url",mbResearchData.getDataImg3());
            m.put("time",mbResearchData.getDataImg3Time());
            img.add(m);
        }
        if(mbResearchData.getDataImg4()!=null){
            Map m = new HashMap();
            m.put("url",mbResearchData.getDataImg4());
            m.put("time",mbResearchData.getDataImg4Time());
            img.add(m);
        }
        if(mbResearchData.getDataImg5()!=null){
            Map m = new HashMap();
            m.put("url",mbResearchData.getDataImg5());
            m.put("time",mbResearchData.getDataImg5Time());
            img.add(m);
        }
        if(mbResearchData.getDataImg6()!=null){
            Map m = new HashMap();
            m.put("url",mbResearchData.getDataImg6());
            m.put("time",mbResearchData.getDataImg6Time());
            img.add(m);
        }
        if(mbResearchData.getDataImg7()!=null){
            Map m = new HashMap();
            m.put("url",mbResearchData.getDataImg7());
            m.put("time",mbResearchData.getDataImg7Time());
            img.add(m);
        }
        if(mbResearchData.getDataImg8()!=null){
            Map m = new HashMap();
            m.put("url",mbResearchData.getDataImg8());
            m.put("time",mbResearchData.getDataImg8Time());
            img.add(m);
        }
        if(mbResearchData.getDataImg9()!=null){
            Map m = new HashMap();
            m.put("url",mbResearchData.getDataImg9());
            m.put("time",mbResearchData.getDataImg9Time());
            img.add(m);
        }
        //返回详细数据
        EntityWrapper ew = new EntityWrapper();
        ew.eq("data_detail_id",dataId);
        List list = mbResearchSetpDataDetailService.selectList(ew);
        return R.ok().put("img",img).put("data",list);
    }
}
